package ord.display;

import java.awt.*;
/*
 * Full File Name:  OMTConnection.java
 *
 * University of Texas at Arlington
 * Software Engineering Center for Telecommunications
 * Object Oriented Testing Project
 *
 * (c) Copyright 1994 University of Texas at Arlington
 * ALL RIGHTS RESERVED
 *
 * Update History:
 * Date       Author   Changes
 * ---------- -------- --------------------
 * 09/28/1999 Bill F.  * Redesigned OMTConnection so it paints itself.
 *                       The ORDCanvas will call paint(g) from its
 *                       paint method.
 *
 * Functional Description:
 * Error Messages        :
 * Constraints           :
 * Assumptions           :
 */

public class OMTConnection
{
   public Point from;
   public Point to;
   public char type;

   OMTConnection(Point from,Point to, char type)
   {
      this.from = from;
      this.to = to;
      this.type = type;
   }

   public void paint(Graphics g)
   {
      /* Note: I didn't save the previous color then restore it for
       * performance reasons.  This gets called many times.  --Bill F.
       */
      if(type=='I')
         g.setColor(Color.red);
      else if(type=='A')
         g.setColor(Color.blue);
      else if(type=='F')
         g.setColor(Color.black);
      else if (type=='R') {
         g.setColor(Color.red);
         double slope=(to.getY()-from.getY())/(to.getX()-from.getX());
         int d=3;
         for(int i=from.x; i<(int)to.x; i=i+2*d) {
           int x1=i, y1=from.y+(int)((i-from.x)*slope);
           int x2=i+d, y2=from.y+(int)(((i-from.x)+d)*slope);
           g.drawLine(x1, y1, x2, y2);
         }
         return;
      }
      g.drawLine(from.x,from.y,to.x,to.y);
   }
}
